package com.ququ.syb.business.withdraw.controller;

import com.ququ.common.result.Result;
import com.ququ.syb.business.withdraw.fegin.WithdrawOrderFegin;
import com.ququ.syb.business.withdraw.service.WithdrawBusinessService;
import com.ququ.syb.common.pojo.WithdrawOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WithdrawBusinessController {
    @Autowired
    private WithdrawBusinessService withdrawBusinessService;
    @Autowired
    private WithdrawOrderFegin withdrawOrderFegin;

    /**
     * 创建提现订单请求（p1001）
     * @param accountid
     * @param tradenum
     * @param outorderno
     * @param amount
     * @param paychannelid
     * @param appcode
     * @param type          1-提现 0-伪直清 2-虚拟提现
     * @param withdrawtype  0-D0  1-D1  2-T1
     * @param callbackurl
     * @return
     */
    @RequestMapping("/withdraw")
    public Result<WithdrawOrder> createWithdrawOrder(@RequestParam String accountid,
                                                     @RequestParam(required = false) String tradenum,
                                                     @RequestParam String outorderno,
                                                     @RequestParam Long amount,
                                                     @RequestParam String paychannelid,
                                                     @RequestParam String appcode,
                                                     @RequestParam(defaultValue = "1") Integer type,
                                                     @RequestParam(defaultValue = "0") Integer withdrawtype,
                                                     @RequestParam String callbackurl){
        return withdrawBusinessService.createWithdrawOrder(accountid, tradenum, outorderno, amount, paychannelid, appcode, type, withdrawtype, callbackurl, null);
    }

    /**
     * 直清订单创建提现订单
     * @param paytradenum
     * @return
     */
    @RequestMapping("/withdraw/direct")
    public Result<WithdrawOrder> createDirectClearWithdraw(@RequestParam String paytradenum){
        return withdrawBusinessService.createWithdrawOrder(null,null,null,null,null,null,null,null,null,paytradenum);
    }

    @RequestMapping("/withdraw/callback")
    public Result<WithdrawOrder> withdrawCallback(@RequestParam String tradenum,
                                                  @RequestParam int status,
                                                  @RequestParam(required = false) String failreason){
        withdrawBusinessService.withdrawCallback(tradenum, status, failreason);
        return withdrawOrderFegin.queryWithdrawOrder(tradenum);
    }
}
